import sys
from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication

class MyWindow(QWidget):

    def __init__(self):
        super().__init__()

        self.setGeometry(100, 100, 300, 200)
        self.show()

    def closeEvent(self, event):

            reply = QMessageBox.question(self, 'My message', 'Are you sure to Quit?', QMessageBox.Yes|QMessageBox.No, QMessageBox.No)

            if reply == QMessageBox.Yes:
                event.accept()

            else:
                event.ignore()

if __name__ == '__main__':

    app = QApplication(sys.argv)
    win = MyWindow()
    sys.exit(app.exec_())
